import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import './plugins/element.js'
import '@/assets/css/public.css'
import 'normalize.css'
import * as API from '@/http/api'
Vue.prototype.$API = API

Vue.config.productionTip = false

new Vue({
    router,
    store,
    render: (h) => h(App)
}).$mount('#app')

// 路由守卫
router.beforeEach((to, from, next) => {
    console.log('to::', to)
    const flag = to.matched.some((item) => {
        return item.meta.state
    })
    if (flag) {
        const token = sessionStorage.getItem('token')
        if (!token) {
            next('/login')
        } else {
            next()
        }
    } else {
        next()
    }
})